package com.xiaofengstu.mcams.web.controller;


import com.xiaofengstu.mcams.annotation.ILog;
import com.xiaofengstu.mcams.dto.BasicResultDTO;
import com.xiaofengstu.mcams.enums.RespStatusEnum;
import com.xiaofengstu.mcams.web.entity.TCampus;
import com.xiaofengstu.mcams.web.service.TCampusService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author fengzeng
 * @since 2022-05-07
 */
@RestController
@RequestMapping("/web/campus")
@RequiredArgsConstructor
public class TCampusController {

  private final TCampusService campusService;

  @ILog("获取校区列表")
  @GetMapping
  public BasicResultDTO<List<TCampus>> getCampusList() {
    return new BasicResultDTO<>(RespStatusEnum.SUCCESS, campusService.list());
  }

  @ILog("通过角色获取校区列表")
  @GetMapping("/listByRole")
  public BasicResultDTO<List<TCampus>> getCampusListByRole() {
    return new BasicResultDTO<>(RespStatusEnum.SUCCESS, campusService.getCampusListByRole());
  }

  @ILog("新增校区")
  @PostMapping("/add")
  public BasicResultDTO<Boolean> add(@RequestBody TCampus campus) {
    return new BasicResultDTO<>(RespStatusEnum.SUCCESS, campusService.save(campus));
  }

  @ILog("更新校区")
  @PostMapping("/update")
  public BasicResultDTO<Boolean> update(@RequestBody TCampus campus) {
    return new BasicResultDTO<>(RespStatusEnum.SUCCESS, campusService.updateById(campus));
  }

  @ILog("通过校区ID删除校区")
  @GetMapping("/del")
  public BasicResultDTO<Boolean> getCampusListByRole(@RequestParam("campusId") Integer campusId) {
    return new BasicResultDTO<>(RespStatusEnum.SUCCESS, campusService.removeById(campusId));
  }


}
